<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>	
	
	<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
	
	<script type="text/javascript">
	function getPixelLength()
	{
		var result = [];
		result.push(getAnswerLength(window.currentSD));
		result.push(getAnswerLength(window.currentD));
		result.push(getAnswerLength(window.currentN));
		result.push(getAnswerLength(window.currentA));
		result.push(getAnswerLength(window.currentSA));
		
		return result;		
	}
	function getAnswerLength(answerCount)
	{
		if(answerCount == 0 || window.currentTotal == 0)
		{
			return 0;
		}
		var returnValue = ((answerCount/window.currentTotal) * window.totalBarLength);
		return returnValue;
	}
	function appendQuestion()
	{
		<!-- window.currentQuestion, window.currentSD, window.currentD, window.currentN, window.currentA, window.currentSA; -->
		$("#array").append('<div style=" float:left;background-color:#e8464a;height:50px;width:'+window.currentLengths[0]+'px;">&nbsp;</div>');
		$("#array").append('<div style=" float:left;background-color:#f4a8aa;height:50px;width:'+window.currentLengths[1]+'px;">&nbsp;</div>');
		$("#array").append('<div style=" float:left;background-color:#f0ecd5;height:50px;width:'+window.currentLengths[2]+'px;">&nbsp;</div>');
		$("#array").append('<div style=" float:left;background-color:#a2d2d7;height:50px;width:'+window.currentLengths[3]+'px;">&nbsp;</div>');
		$("#array").append('<div style=" float:left;background-color:#7092be;height:50px;width:'+window.currentLengths[4]+'px;">&nbsp;</div>');
	}
	var totalBarLength = 400;
	var currentQuestion = " ";
	var currentSD = 0;
	var currentD = 0;
	var currentN = 0;
	var currentA = 0;
	var currentSA = 0;
	var currentTotal = 0;
	var currentLengths = [ ];
	var finishedQuestions = [ ];
	var printedQuestions = [ ];
	
	window.onload=(function() {

		jQuery.get('https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/AnswerCount.cfm?crn=30594&semester=3&year=2013', function(data) {

			$.each(data.DATA, function(i,array) {
				<!-- $("#array2").append( array[0] + " - " + array[1] + " - " + array[2]  + " - "  + array[3]  + " - " + array[4] + "<br>" ); -->

					window.currentQuestion = array[2];
					$.each(data.DATA, function(i,innerArray){
						if(window.currentQuestion == innerArray[2] && window.finishedQuestions.indexOf(window.currentQuestion + " - " + innerArray[3]) == -1)
						{
							switch(innerArray[3])
							{
								case 'strongly disagree' :
									window.currentSD+= +innerArray[4];
									window.currentTotal+= +innerArray[4];
									break;
								case 'disagree' :
									window.currentD+= +innerArray[4];
									window.currentTotal+= +innerArray[4];					
									break;
								case 'neutral' :
									window.currentN+= +innerArray[4];
									window.currentTotal+= +innerArray[4];
									break;
								case 'agree' :
									window.currentA+= +innerArray[4];
									window.currentTotal+= +innerArray[4];
									break;					
								case 'strongly agree' :
									window.currentSA+= +innerArray[4];
									window.currentTotal+= +innerArray[4];
									break;
							}
							
							window.finishedQuestions.push(window.currentQuestion + " - " + innerArray[3]);

						}
					});
					
					if(window.printedQuestions.indexOf(window.currentQuestion) == -1)
					{
						window.currentLengths = getPixelLength();
						window.printedQuestions.push(window.currentQuestion);
						$("#array").append('<p style="clear:both;">' + window.currentQuestion + " - " + window.currentSD + " - " + window.currentD + " - "  + window.currentN + " - " + window.currentA +" - " + window.currentSA +" - " + window.currentTotal + "</p><br>" );
						
						appendQuestion();

					}
					window.currentQuestion = " ";
					window.currentSD = 0;
					window.currentD = 0;
					window.currentN = 0;
					window.currentA = 0;
					window.currentSA = 0;
					window.currentTotal = 0;
						
			});
		});
	});


	
	</script>
	
</head>

<body>
<div id="array2" name="array" ></div>
<div id="array" name="array" style='background-color:#dddddd;'></div>

</body>


<!-- https://chitester1dev.weber.edu:6838/misc/weber/CSEvals/AnswerCount.cfm?crn=XXXXX&semester=X&year=XXXX -->


